﻿using System;

using ZProto;
using ZProto.Message;

namespace ZProtoParser
{
   

    class Args
    {
        public const string HELP = @"
参数:
input=[输入文件路径]
output=[输出文件路径]
monofile=[是否为单文件输出] true:单文件;false:多文件;
    如果为多文件输出，output则为文件目录。
help 帮助
";
        public static string input = "";                            // 输入文件
        public static string template = "";                         // 模板文件
        public static string output_dir = "";                       // 输出目录
        public static string output_file = "";                      // 输出文件 (仅在打包成单个文件时需要)
        public static string suffix = ".cs";                        // 文件后缀
        public static bool monofile = false;
        public static bool Parse(string[] args)
        {
            foreach (var line in args)
            {
                if(line.ToLower() == "help")
                {
                    Console.Write(HELP);
                    Console.ReadKey();
                    return false;
                }
                var strs = line.Split('=');
                if (strs.Length < 2)
                    continue;
                var key = strs[0];
                var value = strs[1];
                if (key == "input")
                    input = value;
                else if (key == "template")
                    template = value;
                else if (key == "output")
                    output_dir = value;
                else if (key == "monofile")
                    Args.monofile = value == "true";
                //System.Console.WriteLine(key + " = " + value);
            }
            if (input == "" || template == "" || (output_dir == "" && output_file == "") || suffix == "")
                return false;
            return true;
        }
    }
    public class Timer
    {
        private static long lastTime;
        private static long curTime;

        public static void beginTime()
        {
            curTime = DateTime.Now.Ticks / 10000;
            lastTime = curTime;
        }

        public static void endTime(string log)
        {
            curTime = DateTime.Now.Ticks / 10000;

            Console.WriteLine(string.Format(" {0} 耗时 : {1} 毫秒.", log, curTime - lastTime));

            lastTime = curTime;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            if (Args.Parse(args))
            {

                Generator.Generate("cs", Args.input, Args.output_dir, Args.monofile);
            }
            
        }
    }
}
